package cn.edu.pku.service;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.pku.constant.EnumStatus;
import cn.edu.pku.entity.UserInfo;
import cn.edu.pku.mapper.UserInfoMapper;
import cn.edu.pku.util.TokenUtil;
import cn.edu.pku.vo.LoginResult;

/**
 * Created by ming.qin on 2017/4/20.
 */
@Service
public class UserInfoService {
    @Autowired
    UserInfoMapper userInfoMapper;

    public LoginResult getByNamePass(String name, String pass) {
        LoginResult result = new LoginResult();
        UserInfo user = userInfoMapper.selectByNamePass(name, pass);
        if (user == null) {
            result.setStatus(-1);
            return result;
        }
        result.setStatus(EnumStatus.SUCCESS.getStatus());
        result.setName(user.getName());
        result.setToken(TokenUtil.generaterToken());
        return result;
    }

}
